package com.lwb.ztx.videos.wedget;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lwb.ztx.R;
import com.lwb.ztx.bean.VideoTypeBean;
import com.lwb.ztx.utils.ListUtils;

import java.util.List;

/**
 * Created by luweibin on 2016/5/31.
 */
public class VideoTypeAdapter extends RecyclerView.Adapter {
    private List<VideoTypeBean> videoTypeBeanList;
    private OnVideoTypeClickListener listener;

    public VideoTypeAdapter(OnVideoTypeClickListener listener) {
        this.listener = listener;
    }

    public void setVideoTypeBeanList(List<VideoTypeBean> videoTypeBeanList) {
        this.videoTypeBeanList = videoTypeBeanList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.video_header_item, parent, false);
        return new TypeViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        TypeViewHolder typeViewHolder = (TypeViewHolder) holder;
        typeViewHolder.type.setText(videoTypeBeanList.get(position).getName());
        typeViewHolder.videoTypeBean = videoTypeBeanList.get(position);
    }

    @Override
    public int getItemCount() {
        return ListUtils.getSize(videoTypeBeanList);
    }
    class TypeViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        TextView type;
        VideoTypeBean videoTypeBean;
        public TypeViewHolder(View itemView) {
            super(itemView);
            type = (TextView) itemView.findViewById(R.id.video_header_type);
            type.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (listener != null) {
                listener.OnVideoTypeClick(videoTypeBean);
            }
        }
    }
    public interface OnVideoTypeClickListener{
        void OnVideoTypeClick(VideoTypeBean videoTypeBean);
    }
}
